/**
 * @file Storage 提供 localStorage 存储和读取功能.
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */


export function put(key, value) {
  value = JSON.stringify(value);
  localStorage.setItem(key, value);
}

export function get(key, defaultValue) {
  let value = localStorage.getItem(key);

  try {
    value = value ? JSON.parse(value) : null;
  } catch (e) {
    // console
  }

  return value || defaultValue;
}

export function remove(key) {
  return localStorage.removeItem(key);
}

export function clear() {
  localStorage.clear();
}
